<template>
	<view>
		<detail-info :item="detail"></detail-info>
		<view class="comment-title">最新评论 {{comment.count}}</view>
		<!-- 评论列表 -->
		<view class="uni-comment comment">
			<block v-for="(item,index) in comment.list" :key="index">
				<comment-list :item="item" :index="index"></comment-list>
			</block>
		</view>
		<!-- 评论 -->
		<chat-input @submit="submit"></chat-input>
		<!-- 分享 -->
		<more-share :showShare="showShare" @toggleShare="toggleShare"></more-share>
	</view>
</template>

<script>
	import detailInfo from "../../components/detail/detail-info.vue"
	import commentList from "../../components/detail/comment-list.vue"
	import chatInput from "../../components/chat/chat-input.vue"
	import moreShare from "../../components/common/more-share.vue"
	import {
		getTime
	} from "../../common/tools/time.js"

	export default {
		data() {
			return {
				showShare:false,
				detail: {
					userpic: "../../static/image/userpic/12.jpg",
					username: "哈哈哈",
					sex: 0, // 0: 男, 1: 女
					age: 23,
					isfollow: false,
					title: "我是标题",
					titlepic: "../../static/image/datapic/13.jpg",
					morepic: [
						"../../static/image/datapic/13.jpg",
						"../../static/image/datapic/12.jpg",
						"../../static/image/datapic/11.jpg",
						"../../static/image/datapic/10.jpg",
						"../../static/image/datapic/11.jpg",
						"../../static/image/datapic/11.jpg",
					],
					video: false,
					share: false,
					site: "深圳 龙岗",
					sharenum: 20,
					commentnum: 30,
					goodnum: 40
				},
				comment: {
					count: 20,
					list: []
				}
			};
		},
		methods: {
			// 获取评论
			getCommentList() {
				let arr = [
					// 一级评论
					{
						id: 1,
						fid: 0,
						userpic: "../../static/common/addinput.png",
						username: "233来了",
						time: "1555400035",
						data: "支持火车2122"
					},
					// 子级评论
					{
						id: 2,
						fid: 1,
						userpic: "../../static/common/addinput.png",
						username: "233来了",
						time: "1555400035",
						data: "支持火车2122"
					},
					{
						id: 3,
						fid: 1,
						userpic: "../../static/common/addinput.png",
						username: "233来了",
						time: "1555400035",
						data: "支持火车2122"
					},
					{
						id: 4,
						fid: 0,
						userpic: "../../static/common/addinput.png",
						username: "233来了",
						time: "1555400035",
						data: "支持火车2122"
					},
					{
						id: 5,
						fid: 4,
						userpic: "../../static/common/addinput.png",
						username: "233来了",
						time: "1555400035",
						data: "支持火车2122"
					},
					{
						id: 6,
						fid: 0,
						userpic: "../../static/common/addinput.png",
						username: "233来了",
						time: "1555400035",
						data: "支持火车2122"
					},
					{
						id: 7,
						fid: 0,
						userpic: "../../static/common/addinput.png",
						username: "233来了",
						time: "1555400035",
						data: "支持火车2122"
					}
				]
				for (let i in arr) {
					arr[i].time = getTime(arr[i].time)
				}
				this.comment.list = arr
			},
			submit(data) {
				let obj = {
					id: 10,
					fid: 0,
					userpic: "../../static/common/addinput.png",
					username: "233来了",
					time: getTime(new Date().getTime()),
					data: data
				}
				this.comment.list.push(obj)
			},
			toggleShare(){
				this.showShare = !this.showShare
			}
		},
		components: {
			detailInfo,
			commentList,
			chatInput,
			moreShare
		},
		onLoad(e) {
			console.log(this.$Route)
			// uni.setNavigationBarTitle({
			// 	title: obj.title
			// })
			this.getCommentList()
		},
		// 监听导航右边按钮
		onNavigationBarButtonTap(e) {
			if (e.index === 0) {
				this.toggleShare()
			}
		}
	}
</script>

<style lang="scss" scoped>
	// 评论
	.comment {
		padding: 0 20upx;
		padding-bottom: 120upx;
	}

	.comment-title {
		padding: 20upx;
		font-size: 30upx;
		font-weight: bolder;
		color: #000000;
	}
</style>
